package com.huage_04.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class JedisPoolUtils {
    public static JedisPool jedisPool;

    static {

        try {
            Properties prop = new Properties();
            prop.load(JedisPoolUtils.class.getClassLoader().getResourceAsStream("jedis.properties"));
            JedisPoolConfig config = new JedisPoolConfig();
            config.setMaxTotal(Integer.parseInt(prop.getProperty("maxTotal")));
            config.setMaxIdle(Integer.parseInt(prop.getProperty("maxIdle")));
            String host = prop.getProperty("host");
            int port = Integer.parseInt(prop.getProperty("port"));
            jedisPool = new JedisPool(config,host,port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static Jedis getJedis(){
        return jedisPool.getResource();
    }

}
